#ifndef FLAG3CONTROL_H
#define FLAG3CONTROL_H

#include <QWidget>
#include <QPushButton>
#include <QSlider>
#include <QLineEdit>
#include <QLabel>
#include <QJsonObject>
#include <QMap>

#include <QJsonParseError>
#include <QJsonArray>
#include <QDebug>
#include <QMap>
#include <QLineEdit>
#include <QMutex>
#include"DeviceManager.h"
#include <QSharedPointer>

class Flag3Control : public QWidget
{
    Q_OBJECT
public:
    explicit Flag3Control(QWidget *parent = nullptr);
    explicit Flag3Control(const QJsonObject &flagDetails, const QString deviceID,QWidget *parent = nullptr);
    ~Flag3Control() override { qDebug() << "[Flag3Control] ~Flag3Control()"; }


    void reset();                        // 重置到默认值
    QLineEdit* getAngleDisplay() const; // 获取输入框指针
    QString getJointName() const;        // 获取标签文本
    void setDefaultPosition(int defaultPosition); // 设置默认滑块值
     void setRange(double min, double max);
public slots:
    // 绑定节点后
    void attachToNode(QSharedPointer<DeviceNode> node);
    void pubMsg(QString content);


signals:
    void angleChanged(const QString &jointName, double angle,QString command);


private:
    void setupControlLayout(const QJsonObject &flagDetails);

    QPushButton *btnDecrease = nullptr;
    QPushButton *btnIncrease = nullptr;
    QSlider *slider = nullptr;
    QLineEdit *lineEdit = nullptr;
    QLabel *label = nullptr;
    QLabel *unitLabel = nullptr;

    double minValue;
    double maxValue; // 可以根据需要调整
    double step = 0.01;      // 精度，和滑块刻度相关
    int m_default = 0;  // 存储乘以100的默认值
    QMap<QString, QString> commandMap;
     bool flagReset;//TURE: 重置消息状态，FALSE:非重置消息状态

    //更改结点架构
    QSharedPointer<DeviceNode> m_node;
    QString mDeviceName;
    QMap<QString,QString> initMsg;

private slots:
    void onSliderValueChanged(int value);
    void onLineEditEditingFinished();
    void onBtnDecreaseClicked();
    void onBtnIncreaseClicked();

    void onDataReceived(const QString& content);
};

#endif // FLAG3CONTROL_H
